import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path*',
    component: () =>
                import('@/views/redirect/index')
  }]
}, {
  name: 'constant-login',
  path: '/login',
  component: () =>
            import('@/views/login/index'),
  hidden: true
},
{
  name: 'constant-404',
  path: '/404',
  component: () =>
            import('@/views/errorPage/404'),
  hidden: true
},
{
  name: 'constant-401',
  path: '/401',
  component: () =>
            import('@/views/errorPage/401'),
  hidden: true
},

{
  path: '',
  component: Layout,
  redirect: 'dashboard',
  children: [{
    path: 'dashboard',
    component: () =>
                import('@/views/dashboard/index'),
    name: 'Dashboard',
    meta: { title: 'dashboard', icon: 'dashboard' }
  }]
}
]

/** 1.这里要注意在创建基础路由表时,一级的虚拟路由（即不在页面菜单中显示的路由项）要加上alwaysShow: false;
 *  2.除虚拟路由外,其他路由项name也要标注清楚;
 */
export const baseRouterMap = [{
  path: '/icon',
  component: Layout,
  hidden: true,
  alwaysShow: false,
  redirect: '/icon/icon-index',
  meta: { title: 'icons', icon: 'icon' },
  children: [{
    path: 'icon-index',
    component: () =>
                import('@/views/svg-icons/index'),
    name: 'Icons',
    meta: { title: 'icons', icon: 'icon', noCache: true }
  }]
}, {
  path: '/example',
  component: Layout,
  hidden: true,
  alwaysShow: true,
  redirect: '/example/table',
  name: 'Example',
  meta: { title: 'Example', icon: 'example' },
  children: [{
    path: 'table',
    name: 'Table',
    hidden: true,
    component: () =>
                    import('@/views/table/index'),
    meta: { title: 'Table', icon: 'table' }
  },
  {
    path: 'tree',
    name: 'Tree',
    hidden: true,
    component: () =>
                    import('@/views/tree/index'),
    meta: { title: 'Tree', icon: 'tree' }
  },
  {
    path: 'complexTable',
    name: 'ComplexTable',
    hidden: true,
    component: () =>
                    import('@/views/complexTable/index'),
    meta: { title: 'ComplexTable', icon: 'complexTable' }
  }
  ]
},

{
  path: '/form',
  component: Layout,
  hidden: true,
  alwaysShow: false,
  redirect: '/form/index',
  meta: { title: 'Form', icon: 'form' },
  children: [{
    path: 'form-index',
    name: 'Form',
    hidden: true,
    component: () =>
                import('@/views/form/index'),
    meta: { title: 'Form', icon: 'form' }
  }]
},

{
  path: '/charts',
  component: Layout,
  hidden: true,
  alwaysShow: false,
  redirect: 'noredirect',
  name: 'Charts',
  meta: {
    title: 'charts',
    icon: 'chart'
  },
  children: [{
    path: 'keyboard',
    hidden: true,
    component: () =>
                    import('@/views/charts/keyboard'),
    name: 'KeyboardChart',
    meta: { title: 'keyboardChart', noCache: true }
  },
  {
    path: 'line',
    hidden: true,
    component: () =>
                    import('@/views/charts/line'),
    name: 'LineChart',
    meta: { title: 'lineChart', noCache: true }
  },
  {
    path: 'mixchart',
    hidden: true,
    component: () =>
                    import('@/views/charts/mixChart'),
    name: 'MixChart',
    meta: { title: 'mixChart', noCache: true }
  }
  ]
},

{
  path: '/tab',
  component: Layout,
  hidden: true,
  alwaysShow: false,
  redirect: '/tab/tab-index',
  meta: { title: 'tab', icon: 'tab' },
  children: [{
    path: 'tab-index',
    component: () =>
                import('@/views/tab/index'),
    name: 'Tab',
    meta: { title: 'tab', icon: 'tab' }
  }]
},

{
  path: '/nested',
  component: Layout,
  hidden: true,
  redirect: '/nested/menu1',
  alwaysShow: true,
  name: 'Nested',
  meta: {
    title: 'Nested',
    icon: 'nested'
  },
  children: [{
    path: 'menu1',
    hidden: true,
    component: () =>
                    import('@/views/nested/menu1/index'), // Parent router-view
    name: 'Menu1',
    meta: { title: 'Menu1', icon: 'list' },
    children: [{
      path: 'menu1-1',
      hidden: true,
      component: () =>
                            import('@/views/nested/menu1/menu1-1'),
      name: 'Menu1-1',
      meta: { title: 'Menu1-1', icon: 'icon' }
    },
    {
      path: 'menu1-2',
      hidden: true,
      alwaysShow: true,
      component: () =>
                            import('@/views/nested/menu1/menu1-2'),
      name: 'Menu1-2',
      meta: { title: 'Menu1-2', icon: 'icon' },
      children: [{
        path: 'menu1-2-1',
        hidden: true,
        component: () =>
                                    import('@/views/nested/menu1/menu1-2/menu1-2-1'),
        name: 'Menu1-2-1',
        meta: { title: 'Menu1-2-1' }
      },
      {
        path: 'menu1-2-2',
        hidden: true,
        component: () =>
                                    import('@/views/nested/menu1/menu1-2/menu1-2-2'),
        name: 'Menu1-2-2',
        meta: { title: 'Menu1-2-2' }
      }
      ]
    },
    {
      path: 'menu1-3',
      hidden: true,
      component: () =>
                            import('@/views/nested/menu1/menu1-3'),
      name: 'Menu1-3',
      meta: { title: 'Menu1-3', icon: 'icon' }
    }
    ]
  },
  {
    path: 'menu2',
    name: 'Menu2',
    hidden: true,
    component: () =>
                    import('@/views/nested/menu2/index'),
    meta: { title: 'menu2', icon: 'list' }
  }
  ]
},

{
  path: 'external-link',
  name: 'External',
  hidden: true,
  alwaysShow: false,
  component: Layout,
  children: [{
    name: 'External-index',
    hidden: true,
    path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
    meta: { title: 'External Link', icon: 'link' }
  }]
}
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
